
package com.jf.cloud.supplier.controller.supplier;

import com.jf.cloud.api.platform.feign.ConfigFeignClient;
import com.jf.cloud.common.constant.ConfigNameConstant;
import com.jf.cloud.common.i18n.I18nMessage;
import com.jf.cloud.common.i18n.LanguageEnum;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.supplier.dto.SupplierUserRegisterDTO;
import com.jf.cloud.supplier.service.SupplierUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Objects;

/**
 * @author zz
 */
@RestController("supplierSupplierUserRegisterController")
@RequestMapping("/ua/supplier_user_register")
@Tag(name = "supplier-供应商账户注册")
public class SupplierUserRegisterController {

    @Autowired
    private SupplierUserService supplierUserService;

    @Autowired
    private ConfigFeignClient configFeignClient;


    @Operation(summary = "账户注册")
    @PostMapping
    public ServerResponseEntity<Void> register(@Valid @RequestBody SupplierUserRegisterDTO supplierRegisterDTO) {
        // 创建并保存用户信息
        supplierUserService.register(supplierRegisterDTO);
        return ServerResponseEntity.success();
    }

    @Operation(summary = "获取供应商注册协议")
    @GetMapping("/get_supplier_register_protocol")
    public ServerResponseEntity<String> getSupplierRegisterProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if(Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_REGISTER_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_REGISTER_PROTOCOL_EN);
        }
    }

    @Operation(summary = "获取供应商合作协议")
    @GetMapping("/get_supplier_protocol")
    public ServerResponseEntity<String> getSupplierProtocol() {
        Integer dbLang = I18nMessage.getLang();
        if(Objects.equals(LanguageEnum.LANGUAGE_ZH_CN.getLang(), dbLang)) {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_SHOP_PROTOCOL_CN);
        } else {
            return configFeignClient.getConfig(ConfigNameConstant.SUPPLIER_SHOP_PROTOCOL_EN);
        }
    }

}
